package com.xbongbong.paas.model.impl;

import com.xbongbong.paas.constant.PaasConstant;
import com.xbongbong.paas.enums.DelEnum;
import com.xbongbong.paas.model.FineClueUserModel;
import com.xbongbong.paas.toolbox.exception.XbbException;
import com.xbongbong.paas.toolbox.util.CollectionsUtil;
import com.xbongbong.paas.toolbox.util.DateTimeUtil;
import com.xbongbong.pro.domain.dao.FineClueUserDao;
import com.xbongbong.pro.domain.entity.FineClueUserEntity;
import com.xbongbong.saas.constant.BasicConstant;
import com.xbongbong.saas.constant.StringConstant;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author lg
 */
@Service("fineClueUserModel")
public class FineClueUserModelImpl implements FineClueUserModel {

    @Resource
    private FineClueUserDao fineClueUserDao;
    @Override
    public Integer insert(FineClueUserEntity entity) throws XbbException {
        Long now = DateTimeUtil.getInt();
        entity.setAddTime(now);
        entity.setUpdateTime(now);
        entity.setDel(0);
        return fineClueUserDao.insert(entity);
    }

    @Override
    public Integer update(FineClueUserEntity entity) throws XbbException {
        long now = DateTimeUtil.getInt();
        entity.setUpdateTime(now);
        return fineClueUserDao.update(entity);
    }

    @Override
    public List findEntitys(Map<String, Object> param) {
        return fineClueUserDao.findEntitys(param);
    }

    @Override
    public Integer getEntitysCount(Map<String, Object> param) {
        return fineClueUserDao.getEntitysCount(param);
    }

    @Override
    public List findEntitysWithoutSub(Map<String, Object> param) {
        return null;
    }

    @Override
    public Integer batchUpdateStaff(String corpid, List<String> userIdList, Integer staff,String userId) {
        return fineClueUserDao.batchUpdateStaff(corpid,userIdList,staff,userId);
    }

    @Override
    public FineClueUserEntity getByKey(String corpid, String userId) {
        return fineClueUserDao.getByKey(corpid,userId);
    }

    @Override
    public FineClueUserEntity getUserByStaff(String corpid, String userId, Integer staff) {
        return fineClueUserDao.getUserByStaff(corpid,userId,staff);
    }

    @Override
    public Integer batchUpdateDosage(String corpid, List<String> userIdList, Integer type, Integer num) {
        return fineClueUserDao.batchUpdateDosage(corpid,userIdList,type,num);
    }

    @Override
    public FineClueUserEntity getSingleUserByCorpid(String corpid) {
        Map<String, Object> param = new HashMap<>(PaasConstant.DEFAULT_INITIAL_CAPACITY);
        param.put(StringConstant.CORPID,corpid);
        param.put(StringConstant.DEL, DelEnum.NORMAL.getDel());
        param.put("start", BasicConstant.ZERO);
        param.put("pageNum",BasicConstant.ONE);
        List<FineClueUserEntity> list = findEntitys(param);
        if (CollectionsUtil.isEmpty(list)) {
            return null;
        }
        return list.get(0);
    }
    
    @Override
    public Integer removeLeaveStaff(String corpid, List<String> userIdList) {
        return fineClueUserDao.removeLeaveStaff(corpid,userIdList);
    }

    @Override
    public void updateBatch(List<FineClueUserEntity> list, String corpid) {
        if (CollectionsUtil.isNotEmpty(list)){
            fineClueUserDao.updateBatch(list,corpid);
        }
    }
}
